﻿// JScript 文件

Ext.onReady(function () {
    // 使用表单提示
    Ext.QuickTips.init();
    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var sm = new Ext.grid.CheckboxSelectionModel();

    var cm = new Ext.grid.ColumnModel([
	    new Ext.grid.RowNumberer(),
		sm,
		{ header: '商品编号', width: 80, align: 'center', dataIndex: 'proNO',
		    renderer:function (data, metadata, record, rowIndex, columnIndex, store) {  
		            var proID = store.getAt(rowIndex).get('proID');
		            return '<a href="../product.aspx?proID=' + proID  + '" target="_blank" >' + data + '</a> '; 
                }   },
		{ header: '商品名称', width: 80, align: 'center', dataIndex: 'proName',
		        renderer:function (data, metadata, record, rowIndex, columnIndex, store) {  
		                    var proID = store.getAt(rowIndex).get('proID');
		                    return '<a href="../product.aspx?proID=' + proID  + '" target="_blank" >' + data + '</a> '; 
                        }   },
		{ header: '时间', width: 120, align: 'center', dataIndex: 'addTime' },
        { header: '客户名', width: 100, align: 'center', dataIndex: 'cusLoginName' },
        { header: '内容', width: 540, align: 'center', dataIndex: 'context' } 
          
	]);

    cm.defaultSortable = true;

    var ds = new Ext.data.GroupingStore({
        proxy: new Ext.data.HttpProxy({
            url: 'ashx/Evaluation_GetByPage.ashx'
        }),
        reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
        },
		[{ name: 'id', mapping: 'eID', type: 'string' }, 
		 { name: 'proID', type: 'int' },
         { name: 'proNO', type: 'string' },
		 { name: 'proName', type: 'string' },
		 { name: 'addTime', type: 'string' },
         { name: 'cusLoginName', type: 'string' },
         { name: 'context', type: 'string' },
         { name: 'title', type: 'string' } 
		])
    });

 
    var paging = new Ext.PagingToolbar({
        pageSize: 20,
        store: ds,
        displayInfo: true,
        displayMsg: '显示第{0}条到{1}条记录，一共{2}条',
        items:
		[
 

		 "-", " ", { text: '删除',
		     tooltip: '删除客户评价',
		     iconCls: 'icon-del',
		     handler: function () {

		         var _record = grid.getSelectionModel().getSelected();
		         if (sm.getCount() == 1) {
		             del_record(_record );
		         } else
		             Ext.Msg.alert('提示', '请选择一条记录！');
		         

		     }
		 } 	     
		],
        emptyMsg: "查询记录为空!"
    });
    var grid = new Ext.grid.EditorGridPanel({
        renderTo: 'grid-div',
        cm: cm,
        ds: ds,
        sm: sm, 
        bbar: paging,
        height: 500,
        border: true,
        bodyStyle: 'width:1020px',
        stripeRows: true,
        title: '系统日志'
    });

    ds.load({ params: { start: 0, limit: 20} });



    function del_record(record) {

        var myMask = new Ext.LoadMask(Ext.getBody(), {
            msg: "Please wait..."
        });
        Ext.Ajax.request({
              url: 'ashx/Evaluation_Del.ashx' ,
            params:{
                 eId:record.data.id  
            },
            success: function (response) {
                ds.load();
                myMask.hide();
            },
            failure: function () { 
                Ext.Msg.alert('提示', '操作失败！');
                myMask.hide();
            }
        });
    }

 


});